package com.mjk.common.core.redis.listener;


import com.mjk.common.core.redis.listener.bean.RedisEventEntity;
import com.mjk.common.core.redis.listener.event.RedisKeyDeleteEventMessageListener;
import com.mjk.common.tools.logger.BizLogger;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.util.ObjectUtils;

import java.util.List;

public class RedisKeyDelListener extends RedisKeyDeleteEventMessageListener {
	//待通知的 监听
	private List<RedisEventEntity> waitListener;
	
	public RedisKeyDelListener(RedisMessageListenerContainer listenerContainer) {
		super(listenerContainer);		
	}
	
	public void setListener(List<RedisEventEntity> waitListener) {		
		this.waitListener = waitListener;
	}
	@Override
	public void onMessage(Message message, byte[] pattern) {
		try{
			if(ObjectUtils.isEmpty(waitListener)){
				//BizLogger.error("reids del key listener is empty");
				return;
			}
			for(RedisEventEntity entity : waitListener){
				if(null!=entity.getMethod()&&null!=entity.getTarget())
					entity.getMethod().invoke(entity.getTarget(), message.toString());
			}
		}catch(Exception e){
			BizLogger.error(e);
		}
	}
}
